/*    */ package net.sourceforge.appgen.databinding;
/*    */ 
/*    */ import java.util.regex.Matcher;
/*    */ import java.util.regex.Pattern;
/*    */ import net.sourceforge.appgen.util.ConventionUtils;
/*    */ import org.eclipse.core.databinding.validation.IValidator;
/*    */ import org.eclipse.core.databinding.validation.ValidationStatus;
/*    */ import org.eclipse.core.runtime.IStatus;
/*    */ 
/*    */ public class PackageNameValidator
/*    */   implements IValidator
/*    */ {
/*    */   public IStatus validate(Object value)
/*    */   {
/* 34 */     if ((value instanceof String)) {
/* 35 */       String s = (String)value;
/*    */ 
/* 37 */       if ((s == null) || (s.length() == 0)) {
/* 38 */         return ValidationStatus.error("Enter the package name.");
/*    */       }
/*    */ 
/* 41 */       if ((s.startsWith(".")) || (s.endsWith("."))) {
/* 42 */         return ValidationStatus.error("Invalid package name. A package name connot start or end with a dot");
/*    */       }
/*    */ 
/* 45 */       String patternExp = "^([_a-zA-Z]+[a-zA-Z0-9_]*)?$";
/* 46 */       Pattern pattern = Pattern.compile(patternExp);
/*    */ 
/* 48 */       String[] packageNames = s.split("[.]");
/* 49 */       if (packageNames.length == 0) {
/* 50 */         packageNames = new String[] { s };
/*    */       }
/*    */ 
/* 53 */       for (String packageName : packageNames) {
/* 54 */         if (packageName.length() == 0) {
/* 55 */           return ValidationStatus.error("Invalid package name. A package name must not contain two consecutive dots");
/*    */         }
/*    */ 
/* 58 */         Matcher matcher = pattern.matcher(packageName);
/*    */ 
/* 60 */         if (!matcher.matches()) {
/* 61 */           return ValidationStatus.error("Invalid package name. '" + packageName + "' is not a valid Java identifier");
/*    */         }
/*    */       }
/*    */ 
/* 65 */       if ((s.equals("java")) || (s.startsWith("java.")) || (s.equals("javax")) || (s.startsWith("javax.")) || 
/* 66 */         (s.equals("org")) || (s.equals("com")) || 
/* 67 */         (s.equals("org.springframework")) || (s.startsWith("org.springframework.")) || 
/* 68 */         (s.equals("org.apache")) || (s.startsWith("org.apache."))) {
/* 69 */         return ValidationStatus.error("Invalid package name. Already existing(using) package name.");
/*    */       }
/*    */ 
/* 72 */       if (ConventionUtils.isReservedWord(s)) {
/* 73 */         return ValidationStatus.error("Invalid package name. Reserved words.");
/*    */       }
/*    */ 
/* 76 */       return ValidationStatus.OK_STATUS;
/*    */     }
/* 78 */     throw new RuntimeException("Not supposed to be called for non-strings.");
/*    */   }
/*    */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.databinding.PackageNameValidator
 * JD-Core Version:    0.6.0
 */